using Microsoft.AspNetCore.Mvc;
using ZR.Admin.WebApi.Filters;
using ZR.Model.System.Dto;
using ZR.ServiceCore.Services.IService;

namespace ZR.Admin.WebApi.Controllers.System
{
    /// <summary>
    /// 激光雷达状态管理
    /// </summary>
    [Verify]
    [Route("system/windLidarStatus")]
    [ApiExplorerSettings(GroupName = "sys")]
    public class WindLidarStatusController : BaseController
    {
        /// <summary>
        /// 激光雷达状态服务
        /// </summary>
        private readonly IWindLidarStatusService WindLidarStatusService;

        public WindLidarStatusController(IWindLidarStatusService windLidarStatusService)
        {
            WindLidarStatusService = windLidarStatusService;
        }

        /// <summary>
        /// 获取激光雷达状态
        /// </summary>
        /// <param name="commandtype">命令类型</param>
        /// <param name="commanddata">命令数据</param>
        /// <returns></returns>
        [HttpGet("status")]
        public async Task<IActionResult> GetStatus([FromQuery] string commandtype = "status", [FromQuery] object commanddata = null)
        {
            try
            {
                var request = new WindLidarStatusRequestDto
                {
                    CommandType = commandtype,
                    CommandData = commanddata
                };
                
                var result = await WindLidarStatusService.GetWindLidarStatusAsync(request);
                return SUCCESS(result);
            }
            catch (Exception ex)
            {
                return ToResponse(ApiResult.Error(500, $"获取激光雷达状态失败: {ex.Message}"));
            }
        }


        /// <summary>
        /// 获取激光雷达状态（公开接口，无需权限）
        /// </summary>
        /// <param name="commandtype">命令类型</param>
        /// <param name="commanddata">命令数据</param>
        /// <returns></returns>
        [HttpGet("public/status")]
        [AllowAnonymous]
        public async Task<IActionResult> GetPublicStatus([FromQuery] string commandtype = "status", [FromQuery] object commanddata = null)
        {
            try
            {
                var request = new WindLidarStatusRequestDto
                {
                    CommandType = commandtype,
                    CommandData = commanddata
                };
                
                var result = await WindLidarStatusService.GetWindLidarStatusAsync(request);
                return SUCCESS(result);
            }
            catch (Exception ex)
            {
                return ToResponse(ApiResult.Error(500, $"获取激光雷达状态失败: {ex.Message}"));
            }
        }
    }
}
